// pages/Goods/goodsOrder/index.js
var common = require("../../../public.js");
Page({

    /**
     * 页面的初始数据
     */
    data: {
        pageNum: 1,
        userInfo: {},
        token: '',
        orderList: [],
        status: 0,
        not: false,
        have: false,
        refreshing: false,
        active: 0,
        stopLoader:false
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        const that = this
        common.getLocalUserInfo(function (success, data) {
            if (success) {
                that.setData({
                    userInfo: data.user,
                    token: data.token
                }, function () {
                    console.log(data, "2222")
                    this.getOrderList(true);
                })
            }
        })
    },
    onChange(event) {
        const id = event.detail.name
        this.setData({
            status: id
        }, () => {
            this.getOrderList()
        })
    },
    getOrderList: function (refresh = false) {
        var that = this;
        let pageNum = refresh ? 1 : this.data.pageNum + 1
        that.setData({
            refreshing: true
        })
        common.post(
            '/storeActivityOrder/getUserActivityOrders',
            {
                userId: that.data.userInfo.id,
                status: that.data.status,
                token: that.data.token,
                pageNum,
                pageSize: 10,
            },
            function (res) {
                if (res.status === 200) {
                    that.data.pageNum = pageNum
              
                    if (!refresh) {
                        console.log("66666666")
                        if (res.data.length == 0) {
                           
                        
                        }else{
                            that.setData({
                                orderList: [...that.data.orderList, ...res.data]
                            })
                        }
                       
                    } else {
                     
                        that.setData({
                            orderList: res.data,

                        })
                    }
                } else {
                    common.showRequestErrMsg(res)
                }

            }, () => {
                that.setData({
                    refreshing: false
                })
            }
        )
    },
    loadMore() {
       
            this.getOrderList(false)
      
    },
    // 封装时间控件方法
    time(time) {
        var now = new Date(time);
        var year = now.getFullYear();
        var month = now.getMonth() + 1;
        var day = now.getDate();
        var hours = now.getHours();
        var minutes = now.getMinutes();
        if (month <= 9) month = '0' + month;
        if (day <= 9) day = '0' + day;
        if (hours <= 9) hours = '0' + hours;
        if (minutes <= 9) minutes = '0' + minutes;
        var shu = year + '-' + month + '-' + day + ' ' + hours + ':' + minutes;
        return shu;
    },
 
  
})